#include "mainwindow.h"

void WeighDataThread::run()
{
    weigh_data_node_cpp = rclcpp::Node::make_shared("weigh_data_node");
    weigh1_sub_ = weigh_data_node_cpp -> create_subscription<std_msgs::msg::Int32>(
        "weigh_talker_1",10,std::bind(&WeighDataThread::weigh1_data_cb, this, std::placeholders::_1));
    weigh2_sub_ = weigh_data_node_cpp -> create_subscription<std_msgs::msg::Int32>(
        "weigh_talker_2",10,std::bind(&WeighDataThread::weigh2_data_cb, this, std::placeholders::_1));
    rclcpp::spin(weigh_data_node_cpp);
}

void WeighDataThread::weigh1_data_cb(const std_msgs::msg::Int32 weigh1_msg)
{
    float w1_data = weigh1_msg.data;
    w1_data = - w1_data / 1000 ;
    weigh1_emit(w1_data);
}

void WeighDataThread::weigh2_data_cb(const std_msgs::msg::Int32 weigh2_msg)
{
    float w2_data = weigh2_msg.data;
    w2_data = - w2_data / 1000 ;
    weigh2_emit(w2_data);
}
